package com.example.lenovo.weiyi;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.com.ruanmeng.utils.CommonUtil;
import com.com.ruanmeng.utils.ToolUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ChangePhonenumberActivity extends BaseActivity {

    @BindView(R.id.et_user_phone)
    EditText etUserPhone;
    @BindView(R.id.iv_phone_name)
    ImageView ivPhoneName;
    @BindView(R.id.bt_queding)
    Button btQueding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_phonenumber);
        ButterKnife.bind(this);
        AddActivity(this);
        ChangLayTitle("更换手机号");
        LayBack();
        init();
    }

    private void init() {
        etUserPhone.addTextChangedListener(this);
    }

    @Override
    public void onTextChanged(CharSequence s, int i, int i1, int i2) {
        super.onTextChanged(s, i, i1, i2);
        if (s.length() > 0) {
            ivPhoneName.setVisibility(View.VISIBLE);
            btQueding.setBackgroundResource(R.drawable.ed_fullmain);
            btQueding.setClickable(true);
        } else {
            ivPhoneName.setVisibility(View.GONE);
            btQueding.setBackgroundResource(R.drawable.ed_fullgeray);
            btQueding.setClickable(false);
        }
    }

    public void doClick(View v) {
        switch (v.getId()) {
            case R.id.bt_queding:
                if (TextUtils.isEmpty(etUserPhone.getText().toString())) {
                    CommonUtil.showToask(ChangePhonenumberActivity.this, "请输入手机号码！");
                    return;
                }
                if (!ToolUtils.isMobileNO(etUserPhone.getText().toString())) {
                    CommonUtil.showToask(ChangePhonenumberActivity.this, "请输入正确的手机号码！");
                    return;
                }
                Intent in = new Intent(ChangePhonenumberActivity.this, ChangetPhoneGetMaActivity.class);
                in.putExtra("phone", etUserPhone.getText().toString());
                startActivity(in);
                break;
            case R.id.iv_phone_name:
                etUserPhone.setText("");
                break;
        }
    }
}
